import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/store'
import Home from '@/components/home/Home'
import Details from '@/components/home/Details'
import Search from '@/components/search/Search'
import Scholar from '@/components/scholar/Scholar'
import Submit from '@/components/submit/Submit'
import Article from '@/components/submit/publish/Article'
import Manuscript from '@/components/submit/management/Manuscript'
import Wiki from '@/components/wiki/Wiki'
import Mine from '@/components/mine/Mine'
import Trends from '@/components/mine/Trends'
import Deliver from '@/components/mine/Deliver'
import Message from '@/components/mine/message/Message'
import ReplyMe from '@/components/mine/message/ReplyMe'
import AtMe from '@/components/mine/message/AtMe'
import ReceivedLikes from '@/components/mine/message/ReceivedLikes'
import SystemNotice from '@/components/mine/message/SystemNotice'
import RankingList from '@/components/rankingList/RankingList'
import SearchList from '@/components/SearchList'
import Login from '@/components/login/Login'
import Register from '@/components/login/Register'
import Forgot from '@/components/login/Forgot'

Vue.use(Router)
// if(localStorage.getItem('token')){
//   store.commit('set_token',localStorage.getItem('token'))
// }
// if(localStorage.getItem('headUrl')){
//   store.commit('changeHeadimg',localStorage.getItem('headUrl'))
// }
//添加以下代码
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  routes: [
    {path: '/', redirect: 'home'},
    {
      path: '/home',
      name: 'Home',
      component: Home
    },
    {
      path: '/login',
      name: 'Login',
      component: Login
    },
    {
      path: '/register',
      name: 'Register',
      component: Register
    },
    {
      path: '/forgot',
      name: 'Forgot',
      component: Forgot
    },
    {
      path: '/searchList',
      name: 'SearchList',
      component: SearchList
    },
    {
      path: '/message',
      name: 'Message',
      component: Message,
      children:[
        {
          path: 'replyMe',
          name: 'ReplyMe',
          component: ReplyMe,
        },
        {
          path: 'atMe',
          name: 'AtMe',
          component: AtMe,
        },
        {
          path: 'receivedLikes',
          name: 'ReceivedLikes',
          component: ReceivedLikes,
        },
        {
          path: 'systemNotice',
          name: 'SystemNotice',
          component: SystemNotice,
        }
      ]
    },
    {
      path: '/rankingList',
      name: 'RankingList',
      component: RankingList
    },
    {
      path: '/details',
      name: 'Details',
      component: Details
    },
    {
      path: '/search',
      name: 'Search',
      component: Search
    },
    {
      path: '/scholar',
      name: 'Scholar',
      component: Scholar
    },
    {
      path: '/submit',
      name: 'Submit',
      component: Submit,
      children:[
        {
          path: 'article',
          name: 'Article',
          component: Article,
        },
        {
          path: 'manuscript',
          name: 'Manuscript',
          component: Manuscript,
        },
      ]
    },
    {
      path: '/wiki',
      name: 'Wiki',
      component: Wiki
    },
    {
      path: '/mine',
      name: 'Mine',
      component: Mine,
      children:[
        {
          path: 'deliver',
          name: 'Deliver',
          component: Deliver,
        }
      ]
    },
  ]
})
